﻿// JS File for SiteCore Puzzle. 2013 Lars Gottlieb 
//
// lLayOutImages: Takes an array of images in the format [{name, url}, ... ,] and adds them to the ImageList 
function layOutImages(array) {
    if (isArray(array)) // Do nothing if input is not recognized. 
        try
        {
            for (i = 0; i < array.length; i++)
                ImageList.innerHTML += '<li><figure><div><img src=\"' + array[i].url + '\" /></div><figcaption>' + array[i].name + '</figcaption></figure></li>';
        }
        catch (e) { }; // Do nothing if input is invalid. 
}
// addTwo is called when the show more button is clicked. It adds two specific images to the ImageList 
function addTwo() {
    layOutImages([{ name: "Image1", url: "http://farm5.staticflickr.com/4010/4578838483_f9c66aece1_z.jpg" }, { name: "Image2", url: "http://farm8.staticflickr.com/7214/7030801869_0dbf5fa4a3_z.jpg" }]);
}

// Tester function to determine if an object happens to be an array 
function isArray(testObject) {
    return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}

// Fluid responsivity
function resize() {
    //Each column is 184px wide; the first one is 64px wider.
    document.getElementById('Wrapper').style.width = (Math.floor((window.innerWidth - 64) / 182) * 182 + 64) + "px";
}
